package com.hw.shortlink.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hw.shortlink.admin.common.convention.response.Result;
import com.hw.shortlink.admin.common.convention.response.Results;
import com.hw.shortlink.admin.remote.dto.ShortLinkRemoteService;
import com.hw.shortlink.admin.remote.dto.req.ShortLinkCreateReqDTO;
import com.hw.shortlink.admin.remote.dto.req.ShortLinkPageReqDto;
import com.hw.shortlink.admin.remote.dto.req.ShortLinkUpdateReqDto;
import com.hw.shortlink.admin.remote.dto.resp.ShortLinkCreateRespDto;
import com.hw.shortlink.admin.remote.dto.resp.ShortLinkPageRespDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class ShortLinkController {
    private final ShortLinkRemoteService shortLinkRemoteService=new ShortLinkRemoteService() {
    };

    /**
     * 新增短锻炼
     * @param shortLinkCreateReqDTO
     * @return
     */
    @PostMapping("/api/short-link/admin/v1/create")
    Result<ShortLinkCreateRespDto> createShortLink(@RequestBody ShortLinkCreateReqDTO shortLinkCreateReqDTO){

        return shortLinkRemoteService.createShortLink(shortLinkCreateReqDTO);
    }

    /**
     * 分页查询
     * @param shortLinkPageReqDto
     * @return
     */
    @GetMapping("/api/short-link/admin/v1/page")
    Result<IPage<ShortLinkPageRespDTO>> pageShortLink(ShortLinkPageReqDto shortLinkPageReqDto){

        return shortLinkRemoteService.pageShortLink(shortLinkPageReqDto);
    }


    /**
     * 修改短链接
     * @param shortLinkUpdateReqDTO
     * @return
     */
    @PostMapping("/api/short-link/admin/v1/update")
    Result<Void> updateShortLink(@RequestBody ShortLinkUpdateReqDto shortLinkUpdateReqDTO){

        shortLinkRemoteService.updateShortLink(shortLinkUpdateReqDTO);
        return Results.success();
    }

}
